#ifndef RENDERER_H
#define RENDERER_H
#include "Defines.h"
#include <d3d9.h>
#include "VertexBuffer.h"
#include "includes.h"
#include "Texture.h"
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

class ENGINE_API Renderer{
public:
	Renderer(HWND hWnd);
	~Renderer();
	void StartFrame();
	void EndFrame();
	void Draw(D3DVERTEX* vertexCollection,D3DPRIMITIVETYPE ePrim,unsigned int uiVertexCount);
	void Draw(TEXTUREVERTEX* vertexCollection,D3DPRIMITIVETYPE ePrim,unsigned int uiVertexCount);
	void SetMatrixMode(MATRIX_MODE mode);
	void LoadIdentity();
	void SetViewportPosition();
	bool LoadTexture(/*const char* _fileName,*/ Texture::ptr _texture);
	bool BindTexture(Texture::ptr _texture);
	void UnBindTexture();
	friend class Entity2D;

private:
	bool InitDX(HWND hWnd);
	IDirect3DDevice9* g_pDirect3D_Device;
	VertexBuffer<D3DVERTEX,COLOR_VERTEX> vBuffer;
	VertexBuffer<TEXTUREVERTEX,TEXTURE_VERTEX> vTextureBuffer;
	D3DXMATRIX projectionMatrix;
	MATRIX_MODE currentMatrixMode;
	D3DXVECTOR3 viewerPos;
	D3DXVECTOR3 viewerUp;

	
	void RotateX(float angle);
	void RotateY(float angle);
	void RotateZ(float angle);
	void Translate(float x,float y,float z);
	void Scale(float widht, float height);

protected:
	map <string, IDirect3DTexture9*> textureMap;
	//typedef map<string, IDirect3DTexture9*>::iterator textureIterator;
	friend class Game;
};
#endif